<?php
define('EmpireCMSAdmin','1');
require_once("../class/connect.php");
require_once("../class/db_sql.php");
require_once("../class/functions.php");
require_once("../class/user.php");
require_once("../class/say.php");
$link=db_connect();
$empire=new mysqlquery();
$s=new say();
$action=$_REQUEST['act'];
$focusDB="phome_jat_focus";
switch($action){
	case "act_focus"://添加状态
		$act_id=$_REQUEST["act_id"];//活动id
		$status=$_REQUEST["status"];
		$app_user_id=$lguserid; 
		$arr=array("uid"=>$app_user_id,"t_uid"=>$act_id,"type_id"=>ACT_FOCUS_ID,"time"=>time(),"status"=>$status);
		//print_r($arr);
		if(!$app_user_id){
			show_error("用户未登录不能关注",-1);	
		}
		if(!emptyArrayTest($arr,array("uid","t_uid"))){			
			show_error("用户字段错误，不能添加,code:".__LINE__);				
		}			
		if(!DbTouch($focusDB,$arr)){
				$falg=DbDataAddOrEdit($focusDB,$arr,array("uid"=>$app_user_id,"t_uid"=>$act_id,"type_id"=>ACT_FOCUS_ID));
				//var_dump($falg);
				show_succ("ok");
		}else{			
			show_error("已经添加不能重复添加");			
		}		
	exit();break;
	case "delete_act_focus":	//取得状态	
		//$d=$s->getLastOne();
		//$d["time"]=getFormatTime($d["time"]);
		//$r=array("flag"=>1,"d"=>$d);
		//echo json_encode($r);
	exit();break;
	case "set_reg_status":	//取得状态	
		if(!$lguserid){show_error("用户未登录");}
		$DB_ACT="phome_ecms_actives";
		$DB_REG="phome_jat_act_registration";
		$id=$_REQUEST["reg_id"];
		$reg=DbTouch($DB_REG,array("id"=>$id));
		if(!$reg){show_error("记录不存在！");}
		$act_id=$reg['act_id'];
		//print_r(array("userid"=>$lguserid,"id"=>$act_id));
		$act=DbTouch($DB_ACT,array("userid"=>$lguserid,"id"=>$act_id));
		if(!$act){show_error("您无权进行操作");}
		$t_status=$_REQUEST['status'];
		$touchArr=array("id"=>$id);		
		if(DbDataAddOrEdit($DB_REG,array("status"=>$t_status),$touchArr)){
			show_error('ok',1);
		}else{
			show_error("系统错误");
		}
	exit();break;
	case "add_pic_ablum":	//取得状态	
		if(!$lguserid){show_error("用户未登录");}		
		$DB_ABLUM="phome_jat_album";
		$num=DbTouch('phome_jat_album',array("uid"=>$lguserid),"count(*) as n");
		 if($num>=DF_LIMIT_USER_ALB_NUM){
			show_error('您已经建立了$num[n]个专辑，不能再建立了！');
		 }
		$title=$_REQUEST["title"];
		$addr=$_REQUEST["addr"];
		$permission=$_REQUEST["permission"];
		$satus=$_REQUEST["title"];
		$content=$_REQUEST["content"];
		$arr=array(
					"uid"=>$lguserid,
					"title"=>enSafeContent(trim($title)),
					"addr"=>enSafeContent($addr),
					"content"=>enSafeContent($content),
					"permission"=>enSafeContent($permission),
					"time"=>time(),
					"status"=>1
				);	
		if($flag=DbAdd($DB_ABLUM,$arr)){
			show_succ($flag,1,array("album_id"=>$flag,"title"=>$title));
		}else{
			show_error("系统错误");
		}
	exit();break;
	case "edit_upoaded_pic":	//取得状态	
		if(!$lguserid){show_error("用户未登录");}
		$files=$_REQUEST;
		$t=$_REQUEST['t'];
		$i=$_REQUEST['i'];
		$db='phome_jat_pic';
		if(is_array($t) && is_array($i)){
			foreach($i as $k=>$v){
				if(empty($i[$k]) || empty($t[$k])){continue;}
				Dbedit($db,array("title"=>$t[$k]),array("id"=>$i[$k]));
			}
			show_succ('ok');
		}elseif(!empty($t) && is_int($i)){
			Dbedit($db,array("title"=>$t),array("id"=>$i));
			show_succ('ok');
		}else{
			show_error('类型不匹配');
		}
		show_error('参数错误');
	exit();break;
	case "edit_tribe_pic":	//取得状态	
		if(!$lguserid){show_error("用户未登录");}
		$files=$_REQUEST;
		$t=$_REQUEST['t'];
		$i=$_REQUEST['i'];
		$db='phome_jat_pic';
		if(is_array($t) && is_array($i)){
			foreach($i as $k=>$v){
				if(empty($i[$k]) || empty($t[$k])){continue;}
				Dbedit($db,array("title"=>$t[$k]),array("id"=>$i[$k]));
			}
			show_succ('ok');
		}elseif(!empty($t) && is_int($i)){
			Dbedit($db,array("title"=>$t),array("id"=>$i));
			show_succ('ok');
		}else{
			show_error('类型不匹配');
		}
		show_error('参数错误');
	exit();break;
	case "add_vote":	//添加投票；
		$id=$_REQUEST['id'];
		$db='phome_enewsinfovote';
		if(empty($lguserid)){show_error('用户未登录！');}
		$data=DbTouch($db,array('id'=>$id));
		$arrVotedData=@explode(',',$data['voteuserid']);
		$arrVotedData=is_array($arrVotedData)?$arrVotedData:array();
		if(@array_search($lguserid,$arrVotedData)){show_error('您已经投票，不能重复投票！');}
		
		array_push($arrVotedData,($lguserid));
		if(empty($data)){show_error('记录不存在！');}
		$arr=array("v1"=>'votetext',"v2"=>'vote1_text',"v3"=>'vote2_text',"v4"=>'vote3_text');
		foreach($arr as $ky=>$vl){
			$num=$_REQUEST[$ky];
			if(empty($num)){show_error('请把信息填写完整！');}
			$DbArr[$vl]=jatAddVoteArea($data[$vl],$num);
		}
		//print_r($arrVotedData);
		$DbArr['voteuserid']=implode(',',$arrVotedData);
		$f=DbEdit($db,$DbArr,array('id'=>$id));	
		DbAddOne($db,array('id'=>$id),'total_vote');
		//$l=DbTouch($db,array("id"=>$id));
		$VD=jatGetVoteInfo($id);
		$total=getVoteTotalNum($VD[0]);
		$per3=(int)($VD[0][2]['num']/($total==0?1:$total)*100);	
		DbEdit('phome_ecms_actives',array('good_vote'=>$per3),array('id'=>$id));		
		show_succ('ok');
	exit();break;
		case "session_id":	//添加投票；
		@session_start();
		$sid=session_id();
		$_SESSION['uid']=$lguserid;
		if($sid){
			show_succ($sid);
		}else{
			show_error('获取不到');
		}
	exit();break;
	case "check_login":	//添加投票；
		@session_start();	
		$sid=session_id();
	
		$_SESSION['uid']=$lguserid;		
		if($lguserid){
			show_succ($lguserid);
		}else{
			show_error('');
		}
	exit();break;
	case "edit_one_pic":
		$_id		= $_REQUEST['i'];
		$_title		= $_REQUEST['t'];
		$_content	= $_REQUEST['c'];
		$db='phome_jat_pic';
		//$deny=;
		$app_userid=$lguserid;
		if(empty($app_userid)){show_error('用户未登录或无权进行修改，编辑失败！');}
		$dt=DbTouch($db,array('id'=>$_id,'uid'=>$app_userid));
		if(empty($dt)){show_error('您无权进行编辑；');}
		DbEdit($db,array('title'=>$_title,'content'=>$_content),array('id'=>$_id));
		show_succ('ok');
	exit();break;
	case "delete_one_pic":
		$_id		= $_REQUEST['i'];	
		$db='phome_jat_pic';		
		$app_userid=$lguserid;
		if(empty($app_userid)){show_error('用户未登录或无权进行修改，删除失败！');}
		$dt=DbTouch($db,array('id'=>$_id,'uid'=>$app_userid));
		if(empty($dt)){show_error('您无权进行操作；');}
		$truepath=$public_r['newsurl'].$dt['url'];
		@unlink($truepath);		
		DbDelete($db,array('id'=>$_id));
		show_succ('ok');
	exit();break;
	case "tribe_relat":
		$_id		= $_REQUEST['i'];
		$_type		= $_REQUEST['type'];
		if($lguserid){
			$dt=DbTouch('phome_jat_jointribe',array('tid'=>$_id,'uid'=>$lguserid));			
			if($_type==1){
				if($dt){
					DbDelete('phome_jat_jointribe',array('tid'=>$_id,'uid'=>$lguserid));
				}
				show_succ('ok');				
			}else{
				if(empty($dt)){				
					if(DbTouch('phome_ecms_tribe',array('id'=>$_id))){
						DbAdd('phome_jat_jointribe',array('tid'=>$_id,'uid'=>$lguserid));
						show_succ('ok');
					}else{
						show_error('记录不存在！');
					}
				}else{
					show_succ('ok');
				}
			}
		}else{
			show_error('用户未登录！');
		}
	exit();break;
}
show_error("no script match");
?>